﻿using AutoSelfApp.Views;
using DevExpress.XtraBars.Docking2010.Views.WindowsUI;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing;
using System.Linq;
using System.Text;

// The data model defined by this file serves as a representative example of a strongly-typed
// model that supports notification when members are added, removed, or modified.  The property
// names chosen coincide with data bindings in the standard item WindowsUIViewApplications.
//
// Applications may use this model as a starting point and build on it, or discard it entirely and
// replace it with something appropriate to their needs.

namespace AutoSelfApp
{
    /// <summary>
    /// Base class for <see cref="SampleDataItem"/> and <see cref="SampleDataGroup"/> that
    /// defines properties common to both.
    /// </summary>
    public class SampleDataCommon
    {
        private string subtitleCore, imagePathCore, descriptionCore, titleCore;

        public string Title
        { get { return titleCore; } }

        public string Subtitle
        { get { return subtitleCore; } }

        public string ImagePath
        { get { return imagePathCore; } }

        public string Description
        { get { return descriptionCore; } }

        public SampleDataCommon(string title, string subtitle, string imagePath, string description)
        {
            titleCore = title;
            subtitleCore = subtitle;
            imagePathCore = imagePath;
            descriptionCore = description;
        }

        public SampleDataCommon()
        { }
    }

    /// <summary>
    /// Generic item data model.
    /// </summary>
    public class SampleDataItem : SampleDataCommon
    {
        private string contentCore, groupNameCore;
        private Color backColorCore;
        private Image iconImageCore;
        private Point imageLocationCore, textLocationCore;
        public IPageCtrl pageCtrl;

        public SampleDataItem(string title, string subtitle, Image iconImage,
            Point imageLocation, Point textLocation, Color backColor, string description, string content, string groupName)
            : base(title, subtitle, "", description)
        {
            backColorCore = backColor;
            contentCore = content;
            groupNameCore = groupName;
            iconImageCore = iconImage;
            imageLocationCore = imageLocation;
            textLocationCore = textLocation;
        }

        public string Content
        { get { return contentCore; } }

        public string GroupName
        { get { return groupNameCore; } }

        public Color BackColor
        { get { return backColorCore; } }

        public Image IconImage
        {
            get { return iconImageCore; }
        }

        public Point ImageLocation
        {
            get { return imageLocationCore; }
        }

        public Point TextLocation
        {
            get { return textLocationCore; }
        }
    }

    /// <summary>
    /// Generic group data model.
    /// </summary>
    public class SampleDataGroup : SampleDataCommon
    {
        private string nameCore;
        private Collection<SampleDataItem> itemsCore;

        public SampleDataGroup(string name)
            : base()
        {
            this.nameCore = name;
            itemsCore = new Collection<SampleDataItem>();
        }

        public SampleDataGroup(string name, string title, string subtitle, string imagePath, string description)
            : base(title, subtitle, imagePath, description)
        {
            this.nameCore = name;
            itemsCore = new Collection<SampleDataItem>();
        }

        public string Name
        { get { return nameCore; } }

        public Collection<SampleDataItem> Items
        { get { return itemsCore; } }

        public bool AddItem(SampleDataItem tile)
        {
            if (!itemsCore.Contains(tile))
            {
                itemsCore.Add(tile);
                return true;
            }
            return false;
        }
    }

    /// <summary>
    /// Generic data model.
    /// </summary>
    internal class SampleDataModel
    {
        private Collection<SampleDataGroup> groupsCore;

        public SampleDataModel()
        {
            groupsCore = new Collection<SampleDataGroup>();
        }

        public Collection<SampleDataGroup> Groups
        { get { return groupsCore; } }

        private SampleDataGroup GetGroup(string name)
        {
            foreach (var group in groupsCore)
                if (group.Name == name) return group;
            return null;
        }

        public bool AddItem(SampleDataItem tile)
        {
            if (tile == null) return false;
            string groupName = tile.GroupName == null ? "" : tile.GroupName;
            SampleDataGroup thisGroup = GetGroup(groupName);
            if (thisGroup == null)
            {
                thisGroup = new SampleDataGroup(groupName);
                groupsCore.Add(thisGroup);
            }
            return thisGroup.AddItem(tile);
        }

        private bool ContainsGroup(string name)
        {
            return GetGroup(name) != null;
        }

        public void CreateGroup(string name, string title, string subtitle, string imagePath, string description)
        {
            if (ContainsGroup(name)) return;
            SampleDataGroup group = new SampleDataGroup(name, title, subtitle, imagePath, description);
            groupsCore.Add(group);
        }
    }

    /// <summary>
    /// Creates a collection of groups and items with hard-coded content.
    ///
    /// SampleDataSource initializes with placeholder data rather than live production
    /// data so that sample data is provided at both design-time and run-time.
    /// </summary>
    internal class SampleDataSource
    {
        private SampleDataModel dataCore;

        public SampleDataSource()
        {
            dataCore = new SampleDataModel();
            String ITEM_CONTENT = String.Format("Item Content: {0}\n\n{0}\n\n{0}\n\n{0}\n\n{0}\n\n{0}",
                        "Curabitur class aliquam vestibulum nam curae maecenas sed integer cras phasellus suspendisse quisque donec dis praesent accumsan bibendum pellentesque condimentum adipiscing etiam consequat vivamus dictumst aliquam duis convallis scelerisque est parturient ullamcorper aliquet fusce suspendisse nunc hac eleifend amet blandit facilisi condimentum commodo scelerisque faucibus aenean ullamcorper ante mauris dignissim consectetuer nullam lorem vestibulum habitant conubia elementum pellentesque morbi facilisis arcu sollicitudin diam cubilia aptent vestibulum auctor eget dapibus pellentesque inceptos leo egestas interdum nulla consectetuer suspendisse adipiscing pellentesque proin lobortis sollicitudin augue elit mus congue fermentum parturient fringilla euismod feugiat");
            /*dataCore.CreateGroup("萧山二院自助服务终端",
                    "萧山二院自助服务终端",
                    "萧山二院自助服务终端",
                    typeof(MainForm).Namespace + ".Assets.DarkGray.png",
                    "萧山二院自助服务终端");*/
            dataCore.AddItem(new SampleDataItem("药品查询",
                "药品查询",
                global::AutoSelfApp.Properties.Resources.yaopin,
                new Point(10, 50),
                new Point(80, 50),
                Color.DarkGreen,
                "查询药品收费信息",
                ITEM_CONTENT,
                "萧山二院自助服务终端"));
            dataCore.AddItem(new SampleDataItem("物价查询",
                "物价查询",
                global::AutoSelfApp.Properties.Resources.wujia,
                new Point(10, 50),
                new Point(80, 50),
                Color.DarkBlue,
                "查询物价收费信息",
                ITEM_CONTENT,
                "萧山二院自助服务终端"));
            dataCore.AddItem(new SampleDataItem("院内导航",
                "院内导航",
                global::AutoSelfApp.Properties.Resources.guide,
                new Point(10, 50),
                new Point(70, 50),
                Color.Coral,
                "查询本院的院内导航",
                ITEM_CONTENT,
                "萧山二院自助服务终端"));
        }

        public SampleDataModel Data
        { get { return dataCore; } }
    }
}